<!--
 * Created by PhpStorm.
 * User: jackhhy
 * Date: 2019/7/24-16:58
 * Link: https://gitee.com/luckygyl/LuckyAdmin
 * FileName: index.html
 *-->


{include file="public/head" /}

<body>
<!-- 正文开始 -->
<div class="layui-fluid">

    <div class="layui-row layui-col-space10">

        <div class="layui-col-md12">

            <div class="layui-card">
                <div class="layui-card-body layui-row ">
                    <form action="" class="layui-form" method="get" >
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">文章搜索：</label>
                                <div class="layui-input-inline">
                                    <input name="title" class="layui-input" value="" type="text" placeholder="请输入标题">
                                </div>
                            </div>

                            <div class="layui-inline" style="padding-left: 20px;">
                                <button class="layui-btn icon-btn" lay-filter="search" lay-submit="">
                                    <i class="layui-icon"></i>搜索
                                </button>
                                <button class="layui-btn icon-btn layui-btn-normal"  onclick="javascript:window.location.reload();" >
                                    <i class="layui-icon layui-icon-refresh"></i> 重置
                                </button>
                            </div>

                        </div>

                    </form >
                </div>

            </div>


            <div class="layui-card">
                <div class="layui-card-header" style="line-height: 55px;">
                    <div class="layui-btn-container do_btn">
                        <button class="layui-btn layui-btn-sm layui-btn-danger"  data-type="del"><i class="layui-icon layui-icon-delete"></i>删除</button>
                        <button class="layui-btn layui-btn-sm layui-btn-primary"  data-type="reload"> <i class="fa fa-refresh"></i> 刷新</button>
                        <button class="layui-btn layui-btn-sm layui-btn-warm"   data-type="check"> <i class="layui-icon layui-icon-spread-left"></i>批量审核</button>
                    </div>
                </div>
                <div class="layui-card-body">

                    <div class="yys-fluid yys-wrapper">
                        <div class="layui-row lay-col-space20">
                            <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                                <section class="yys-body">
                                    <div class="yys-body-content clearfix changepwd">
                                        <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                            <div class="user-tables">
                                                <table id="tableFilter" lay-filter="tableFilter"> </table>
                                            </div>
                                        </div>
                                    </div>
                                </section>
                            </div>
                        </div>
                    </div>

                </div>
            </div>


        </div>


    </div>


</div>



<!--模板-->
<script type="text/html" id="operationTpl">
    <a href="javascript:;"   class="layui-btn layui-btn-danger layui-btn-xs "  onmouseover="tis(this)"  data-title="删除评论" lay-event="del"><i class="layui-icon " >&#xe640;</i></a>
</script>


<script type="text/html" id="status">
    <input type="checkbox" name="status"  lay-data="{{d.status}}" value="{{d.id}}"  lay-filter="sexDemo" lay-skin="switch"  lay-text="已审核|未审核"  {{ d.status == 1 ? 'checked' : '' }}>
</script>

{include file="public/js" /}


<script>
    layui.config({
        base: "{__FRAME_PATH}/js/soultable/",   // 模块目录
        version: 'v1.0'
    }).extend({                         // 模块别名
        soulTable: 'soulTable'
    });
    layui.use(['element', 'table', 'form', 'jquery', 'laydate','util','soulTable'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var laydate = layui.laydate;
        var util=layui.util;
        var  soulTable = layui.soulTable;

        form.render();

        // layer.load(2);
        table.render({
            elem: '#tableFilter',
            url:"{:url('comment/index')}",
            //toolbar: '#toolbarDemo',
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:15
                ,limits:[15,30,40,60,80,100]
            },
            height: $(document).height() - $('#tableFilter').offset().top - 20,
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {type: 'checkbox'},
                // {field: 'id',  title: 'ID',width:60},
                {field: 'title_show',filter: true,style:'cursor: pointer;',title: '用户名',minWidth: 120},
                {field: 'article_title',style:'cursor: pointer;',title: '文章名称',width: 220},
                {field: 'content',style:'cursor: pointer;',title: '评论内容',minWidth: 300},
                {field: 'zan',style:'cursor: pointer;',title: '点赞数量',width: 120,sort:true},
                {field: 'status',style:'cursor: pointer;',title: '状态',width: 120,templet:"#status"},
                {field: 'ip',style:'cursor: pointer;',title: 'IP',width: 140},
                {field: 'browse',style:'cursor: pointer;',title: '浏览器',width: 150},
                {field: 'time_formt', title: '评论时间',align: 'center',width:180},
                {templet: '#operationTpl', width: 100, align: 'center', title: '操作'}
            ]],
            filter: {
            items:['column','data','condition','editCondition','excel'] //用于控制表头下拉显示，可以控制顺序、显示
                ,bottom: true // 是否显示底部筛选区域，默认为true
            },
            done: function (res) {
                soulTable.render(this);
                layer.closeAll('loading');
                hoverOpenImg();
            }
        });


        /**
         * 鼠标悬浮显示大图
         *
         */
        function hoverOpenImg(){
            var img_show = null; // tips提示
            $('td img').hover(function(){
                var img = "<img class='img_msg' src='"+$(this).attr('src')+"' style='width:100%;max-height: 600px;' />";
                img_show = layer.tips(img, this,{
                    tips:[2, 'rgba(41,41,41,.0)']
                    ,area: ['12%']
                });
            },function(){
                layer.close(img_show);
            });
        }


        /**
         * 监听是否显示操作
         */
        form.on('switch(sexDemo)', function(obj){
            var _id=parseInt(obj.value);
            var pan=obj.elem.checked;
            var status;
            if (pan===false){
                status=2;
            }else {
                status=1;
            }
            change_status("table_id","comment",_id,"status",status, obj.othis);
        });

        /**
         * 表格搜索
         */
        form.on('submit(search)', function (obj) {
            CreateSearch("table_id",obj.field); //查询
            return false;
        });



        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            // console.log(JSON.stringify(data));
            var _id=parseInt(data.id);
            var layEvent = obj.event;

            if(layEvent==="del"){
                delete_data(_id,"{:url('comment/delete')}","table_id");
            }
            else {
                layer.msg("功能待开发",{time:1500});return false;
            }

        });


        var active = {
            del: function(){ //获取选中数据
                var checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                delete_data(id,"{:url('comment/delete')}","table_id");
            },
            reload: function(){
                CreateReload("table_id");
            },
            check:function () {
                var checkStatus = table.checkStatus('table_id'),data = checkStatus.data;
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                var ids = id.join(',');

                layer.confirm("确定批量审核通过？", function(index){
                    layer.close(index);
                    $.ajax({
                        beforeSend:function(){
                            layer.load(2);
                        },
                        url: "{:url('comment/check_ok')}",
                        type: "POST",
                        async: true,
                        dataType: "json",
                        data:{
                            ids: ids,
                        },
                        error: function(error) {
                            layer.msg("服务器错误或超时");
                            return false;
                        },
                        success: function(data) {
                            if (data.code==1) {
                                layer.msg(data.msg,{icon:1,time:1500,shade:0.3,anim:4});
                                setTimeout(function(){
                                    CreateReload("table_id");
                                    //重载表格数据
                                },500);
                            }else{
                                layer.msg(data.msg,{icon:15,time:1500,shade:0.3},function () {
                                    CreateReload("table_id");
                                });
                            }
                        },
                        complete:function(){
                            layer.closeAll('loading');
                        }
                    });
                });

            }

        };

        $('.do_btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script >

</body >


</html >